package net.alan.modules.repository;

import net.alan.modules.bean.UserProject;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author 李岩飞
 * Email eliyanfei@126.com
 * 2017/11/22
 */
public interface UserProjectRepository extends JpaRepository<UserProject, Integer> {

    List<UserProject> findByProjectId(Integer projectId);

    UserProject findByProjectIdAndUserId(Integer projectId, Integer userId);

    Integer countByProjectId(Integer projectId);

    @Modifying
    @Transactional
    @Query(value = "delete from userproject where project_id = ?1 and user_id = ?2", nativeQuery = true)
    void deleteByProjectIdAndUserId(Integer projectId, Integer userId);
}
